import request from "@/utils/request";
import store from "@/store/index";
/**
 * 判断当前用户是否为租户
 *
 * @returns {boolean} 当前用户是否为租户
 */
export function isTenant() {
  return !!store.getters.userInfo.tenantId;
}
/**
 * 获取应用版本码
 *
 * @returns {string} 应用版本码
 */
export function appVerCode() {
  return store?.getters?.userInfo?.chooseAppVerCode;
}
/**
 * 获取数据中心上下文
 *
 * @returns {string} 数据中心上下文，根据是否为租户返回"/event"或"/ttdevice"
 */
function dataCenterContext() {
  return isTenant() ? "/event" : "/ttdevice";
}
/**
 * 设备上下文
 *
 * @returns {string} 设备上下文路径
 */
function deviceContext() {
  return isTenant() ? "/device" : "/ttdevice";
}
/**
 * 获取 BDM 上下文路径
 *
 * @returns {string} BDM 上下文路径
 */
function bdmContext() {
  return isTenant() ? "/bdm" : "/ttbdm";
}

/**
 * 获取事件上下文
 *
 * @returns {string} 返回事件上下文字符串
 */
function eventContext() {
  return isTenant() ? "/event" : "/ttevent";
}
/* 查询底部算法功能 */
export function getFunction(data) {
  return request({
    url: "/device/video/algorithm/getFunction",
    method: "post",
    data,
  });
}

/* 查询功能详情 */
export function getFunctionDetail(data) {
  return request({
    url: `device/video/algorithm/getFunctionDetail/${data}`,
    method: "get",
  });
}

/* 获取铁塔用户级别 */
export function getTTLevel(data) {
  return request({
    url: "/ttdevice/video/getTTLevel",
    method: "post",
    data,
  });
}
/* 客户视角 */
/* 统计告警事件信息*/
export function getEventNumNew(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: dataCenterContext() + "/workbench/getEventNumNew",
    method: "post",
    data,
  });
}

/* 获取视频树 */
export function getMonitorTree(data) {
  let url = "/video/getMonitorTree";
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data,
  });
}

/* 获取视频树 */
export function getMonitorOrgTree(data) {
  let url = "/video/getMonitorTree";
  if (isTenant()) {
    data.appVerCode = appVerCode();
    data.queryType = 2;
  } else {
    url = "/ttview/device/getMonitorTreeByAreas";
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data,
  });
}

//查询视频树（客户&铁塔）
export function getMonitorLabelTree(data) {
  let url = "/video/getMonitorTree";
  if (isTenant()) {
    data.appVerCode = appVerCode();
    data.queryType = 4;
  } else {
    url = "/video/getLabelTree";
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data,
  });
}
//查询视频树-铁塔
export function getMonitorLabelTreeTd(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/getLabelTree",
    method: "post",
    data,
  });
}

/* 获取网格树 */
export function getGridTree(data) {
  return request({
    url: bdmContext() + "/grid/getGridTree",
    method: "post",
    data,
  });
}

/* 查询网格员分布列表*/
export function getList(data) {
  return request({
    url:
      bdmContext() +
      `/gridKeeper/getList?pageSize=${data.pageSize}&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/* 客户视角-资源树*/
export function getResourceTree(data) {
  return request({
    url: bdmContext() + `/resource/getResourceTree`,
    method: "post",
    data,
  });
}

/* 资源详情 */
export function getResourceInfo(id) {
  return request({
    url: bdmContext() + `/resource/getResourceInfo?resourceId=${id}`,
    method: "get",
  });
}

/* 网格员信息详情 */
export function gridKeeper(id) {
  return request({
    url: bdmContext() + `/gridKeeper/findOne?keeperId=${id}`,
    method: "get",
  });
}

/* 网格信息详情 */
export function gridKeeperWg(id) {
  return request({
    url: bdmContext() + `/grid/findOne?gridId=${id}`,
    method: "get",
  });
}

/* 客户视角-获取网格员树形列表*/
export function getGridKeeperTree(data) {
  return request({
    url: bdmContext() + `/gridKeeper/getGridKeeperTree`,
    method: "post",
    data,
  });
}

/* 获取客户告警声音信息 */
export function getAlarmVoiceUrl() {
  return request({
    url: "event/AlarmSound/selectByTenantId",
    method: "get",
  });
}
/* 关闭消息稍后提醒 */
export function offDealyMessage(data) {
  return request({
    url: "event/alarm/dealyMessage/updateDealyMessageList",
    method: "post",
    data,
  });
}
/* 判断事件是否有权限 */
export function getOrderIfEdit(param) {
  return request({
    url: "event/alarm/order/getOrderIfEdit",
    method: "post",
    data: param,
  });
}
export function pointsValid(query) {
  return request({
    url: "/video-video/video/query/pointsValid",
    method: "post",
    data: query,
  });
}

export function getReasonList(data) {
  return request({
    url: eventContext() + "/alarm/reason/list",
    method: "post",
    data,
  });
}

//自定义树下拉框查询
export function getDevicecDiyList(data) {
  return request({
    url: deviceContext() + "/deviceDiy/getList",
    method: "post",
    data,
  });
}

//自定义树
export function getDiyTree(data) {
  return request({
    url: deviceContext() + "/deviceDiy/getDiyTree",
    method: "post",
    data,
  });
}
